using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;

namespace star_questionnair.Models
{
    [Table("questionnaire")]
    public class Questionnaire
    {
        [Column("id")]
        public int Id { get; set; }

        [Column("title")]
        public string Title { get; set; }
        
        [Column("description")]
        public string Description { get; set; }
        
        [Column("created_time")]
        public DateTime CreatedTime { get; set; }
        [Column("updated_time")]
        public DateTime UpdatedTime { get; set; }
        [Column("author_id")]
        public int AuthorId { get; set; }
        [Column("deadline")]
        public DateTime Deadline { get; set; }
        [Column("status")]
        public bool Status { get; set; }
        [NotMapped]
        public long Count { get; set; } // 问卷被填写的次数

        [NotMapped]
        public ICollection<Question> Questions { get; set; }
        
        [NotMapped]
        [JsonIgnore]
        public ICollection<Response> Responses { get; set; } // 导航属性

        public Questionnaire()
        {
            Responses = new List<Response>();
            Questions = new List<Question>();
        }

        public Questionnaire(int id, string title, string description, DateTime createdTime, DateTime updatedTime, int authorId, DateTime deadline, bool status)
        {
            Id = id;
            Title = title;
            Description = description;
            CreatedTime = createdTime;
            UpdatedTime = updatedTime;
            AuthorId = authorId;
            Deadline = deadline;
            Status = status;
            Count = 0;
            Responses = new List<Response>();
            Questions = new List<Question>();
        }

        public int GetQuestionnaireId()
        {
            return Id;
        }

        public bool GetStatus()
        {
            return Status;
        }
    }
}